<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initialscale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <form action="save" @submit.prevent="onSubmit">
            <input type="text" name="name" v-model="user.username">
            <button type="submit">保存</button>
        </form>
    </div>
    <script src="vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
               user:{} 
            },
            methods:{
                onSubmit() {
                    if(this.user.uesrname) {
                        console.log("提交表单")
                    } else {
                        alert("请输入用户名")
                    }
                }
            }
        })
    </script>
</body>

</html>